package com.sc.nft.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.IdcardInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sc.nft.entity.vo.DaoLastMonthUserInfoVO;
import com.sc.nft.entity.vo.IdcardInfoVO;
import com.sc.nft.entity.vo.UserTelPageVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * (sc_idcard_info)数据Mapper
 *
 * @author kancy
 * @since 2022-06-01 18:12:41
 * @description 由 Mybatisplus Code Generator 创建
*/
@Mapper
public interface IdcardInfoMapper extends BaseMapper<IdcardInfo> {


    IdcardInfo findLastOneByUserId(@Param("userId") Long userId);

    /**
     * 分页条件查询身份列表
     * @param name
     * @param userTel
     * @param userEmail
     * @return
     */
    Page<IdcardInfoVO> pageIdCard(Page page,@Param("name") String name,@Param("userTel") String userTel, @Param("userEmail")String userEmail,@Param("imgHost")String imgHost);

    IdcardInfo getListByUserId(@Param("userId") Long userId);

    /**
     * 获取用户账号信息分页列表（用于修改手机号展示）
     * @param page
     * @param userTel
     * @return
     */
    IPage<UserTelPageVO> userTelRecordPage(Page page, @Param("userTel") String userTel);


    @Select("select date_format(create_time,'%Y-%m-%d') as create_date ,count(*)  as real_name_count from sc_idcard_info where user_id in (select relevance_id from sc_user_relevance where user_id=#{userId}) and is_delete=0 and is_pass=1 and create_time>#{startTime} group by date_format(create_time,'%Y-%m-%d')")
    List<DaoLastMonthUserInfoVO> getLastMonthCardInfo(@Param("userId") Long userId, @Param("startTime") Date startTime);
}
